﻿using System.Collections.Generic;
using System.Linq;

namespace FinMkts
{
    /// <summary>
    /// A <see cref="Customer"/> has a <see cref="Position"/> in a <see cref="Market"/> when
    /// the <see cref="Customer"/> has one or more long <see cref="Order"/> not balaenced by opposing short <see cref="Order"/>
    /// </summary>
    public class Position
    {
        /// <summary>
        /// Who is the order for
        /// </summary>
        public Customer Customer { get; set; }

        /// <summary>
        /// The market the position is in
        /// </summary>
        public MarketListing Market { get; set; }

        /// <summary>
        /// The orders that make up the position
        /// </summary>
        public IEnumerable<Order> Orders { get; set; }

        /// <summary>
        /// The total amount (position) in the <see cref="Market"/> from a particular <paramref name="viewpoint"/>
        /// </summary>
        public decimal GetTotalAmount(OrderAmountViewpoint viewpoint)
        {
            return Orders.Sum(order => order.GetAmount(viewpoint));
        }
    }
}